﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NETCORE.OdataRestful.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            
            Console.WriteLine("调用-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            return Ok(new List<Node>());
            //return Ok(new string[] { "value1", "value2" });

            var ns = new List<Node>();

            var rr = new Random().Next(1, 10);

            if (rr > 2)
            {
                ns.Add(new Node()
                {
                    id = 1,
                    name = "11name",
                    parentId = "0",
                    updatedAt = DateTime.Now.Ticks / 1000,
                    _deleted = true
                });
            }


            if (rr > 5)
            {
                ns.Add(new Node()
                {
                    id = 3,
                    name = "12name",
                    parentId = "0",
                    updatedAt = DateTime.Now.Ticks / 1000,
                    _deleted = false
                });
            }


            if (rr > 8)
            {
                ns.Add(new Node()
                {
                    id = 3,
                    name = "3name",
                    parentId = "0",
                    updatedAt = DateTime.Now.Ticks / 1000,
                    _deleted = false
                });
            }



            return Ok(ns);
        }


        public class Node
        {
            public long id { get; set; }
            public string name { get; set; }
            public string parentId { get; set; }
            public long updatedAt { get; set; }
            public bool _deleted { get; set; }
        }



        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
